import dayjs from 'dayjs'
import { ref, onBeforeUnmount } from 'vue'
// 封装登录页面时间提示
export const getTime = () => {
  let message = ''
  const hours = new Date().getHours()
  if (hours < 9) {
    message = '早上好'
  } else if (hours < 12) {
    message = '上午好'
  } else if (hours < 14) {
    message = '中午好'
  } else if (hours < 18) {
    message = '下午好'
  } else {
    message = '晚上好'
  }
  return message
}

// 时间
export const formatTime = () => {
  let timer = null
  const time = ref(dayjs().format('YYYY-MM-DD HH:mm:ss'))
  timer = setInterval(() => {
    time.value = dayjs().format('YYYY-MM-DD HH:mm:ss')
  }, 1000)
  onBeforeUnmount(() => {
    clearInterval(timer)
  })
  return time
}
